package org.example.common;

public class ResponseEntity <T> {
    public T data;
    public Boolean success;
    public String msg;

    public ResponseEntity() {}

    public ResponseEntity(T data, Boolean success, String msg) {
        this.data = data;
        this.success = success;
        this.msg = msg;
    }

    public static <T> ResponseEntity<T> ok() {
        return new ResponseEntity<>(null, true, "success");
    }

    public static <T> ResponseEntity<T> ok(T data) {
        return new ResponseEntity<>(data, true, "success");
    }

    public static <T> ResponseEntity<T> ok(T data, String msg) {
        return new ResponseEntity<>(data, true, msg);
    }

    public static <T> ResponseEntity<T> fail() {
        return new ResponseEntity<>(null, false, "fail");
    }

    public static <T> ResponseEntity<T> fail(String msg) {
        return new ResponseEntity<>(null, false, msg);
    }

    public static <T> ResponseEntity<T> fail(T data, String msg) {
        return new ResponseEntity<>(data, false, msg);
    }

    // 添加error方法
    public static <T> ResponseEntity<T> error(String msg) {
        return new ResponseEntity<>(null, false, msg);
    }

    /* ---------- Getter/Setter ---------- */

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    /* ---------- toString ---------- */

    @Override
    public String toString() {
        return "ResponseEntity{" +
                "data=" + data +
                ", success=" + success +
                ", msg='" + msg + '\'' +
                '}';
    }
}